package com.hxkcloud.nurse.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.ArticleKindChildBean;

import java.util.List;

/**
 * Created by ray_lei on 2016/7/6.
 */
public class KindApater extends BaseAdapter {

    private List<ArticleKindChildBean> kindChilds;

    private LayoutInflater mInflater;//得到一个LayoutInfalter对象用来导入布局

    private Context context;

    private String selectChildId;

    /**构造函数*/
    public KindApater(Context context,List<ArticleKindChildBean> kindChilds) {
        this.mInflater = LayoutInflater.from(context);
        this.kindChilds = kindChilds;
        this.selectChildId = selectChildId;
        this.context = context;
    }

    public void setData(List<ArticleKindChildBean> kindChilds) {
        this.kindChilds = kindChilds;
        notifyDataSetChanged();
    }
    public void clearData() {
        kindChilds.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return kindChilds.size();//返回数组的长度
    }

    @Override
    public Object getItem(int position) {
        return kindChilds.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    /**书中详细解释该方法*/
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        Log.v("MyListViewBase", "getView " + position + " " + convertView);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.kind_item_list,null);
            holder = new ViewHolder();
            holder.layout = (LinearLayout) convertView.findViewById(R.id.kind_layout);
            holder.name = (TextView) convertView.findViewById(R.id.kind_tv_name);
            holder.ischoose = (Button) convertView.findViewById(R.id.kind_btn);
            convertView.setTag(holder);
        }
        else{
            holder = (ViewHolder)convertView.getTag();
        }

        holder.name.setText(kindChilds.get(position).getName());
        if(kindChilds.get(position).isChoosed()){
            holder.name.setTextColor(context.getResources().getColor(R.color.light_blue));
            holder.ischoose.setVisibility(View.VISIBLE);
        }else{
            holder.name.setTextColor(context.getResources().getColor(R.color.grey_text1));
            holder.ischoose.setVisibility(View.INVISIBLE);
        }





        return convertView;
    }



/**存放控件*/
public final class ViewHolder{
    public LinearLayout layout;
    public TextView name;
    public Button ischoose;
        }
}
